package com.zy.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zy.entity.Customer;
import com.zy.service.CustomerService;
import com.zy.service.impl.CustomerServiceImpl;

/**
 * Servlet implementation class AddCustServlet
 */
@WebServlet("/AddCustServlet")
public class AddCustServlet extends HttpServlet {
	CustomerService cs = new CustomerServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Customer customer = new Customer();
		
		customer.setCustName(request.getParameter("custname"));
		customer.setCustSource(request.getParameter("custsource"));
		customer.getDict().setDid(Integer.parseInt(request.getParameter("custlevel")));
		customer.setCustPhone(request.getParameter("custphone"));
		customer.setCustMobile(request.getParameter("custmobile"));
		
		cs.insertCustomer(customer);
		response.sendRedirect(request.getContextPath()+"/PageLimitServlet?currentPage=1");
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
